package cn.itcast.goods.category.service;

import java.sql.SQLException;
import java.util.List;

import cn.itcast.goods.category.dao.CategoryDao;
import cn.itcast.goods.category.domain.Category;

/**
 * 分类模块业务层
 * @author HL
 *
 */
public class CategoryService {
	private CategoryDao categoryDao = new CategoryDao();
	
	public List<Category> findAll() {
		try {
			return categoryDao.findAll();
		} catch (SQLException e) {
			throw new RuntimeException(e);
		}
	}

	public void addCategory(Category category) {
		try {
			categoryDao.addCategory(category);
		} catch (SQLException e) {
			throw new RuntimeException(e);
		}
	}

	public List<Category> findAllParents() {
		try {
			return categoryDao.findAllParents();
		} catch (SQLException e) {
			throw new RuntimeException(e);
		}
	}

	public Category findByCid(String cid) {
		try {
			return categoryDao.findByCid(cid);
		} catch (SQLException e) {
			throw new RuntimeException(e);
		}
	}

	public void updateCategory(Category category) {
		try {
			categoryDao.updateCategory(category);
		} catch (SQLException e) {
			throw new RuntimeException(e);
		}
	}
	
	public List<Category> findByParent(String pid) {
		try {
			return categoryDao.findByParent(pid);
		} catch (SQLException e) {
			throw new RuntimeException(e);
		}
	}

	public void deleteCategory(String cid) throws SQLException   {
		
			categoryDao.deleteCategory(cid);
		
	}

	public List<Category> findAllChildren(String cid) {
		try {
			return categoryDao.findAllChildren(cid);
		} catch (SQLException e) {
			throw new RuntimeException(e);
		}
	}
}
